import request from '@/utils/request';
import { baseurl } from './baseurl';
import { hasIsSw,isLianxiSite} from '../utils/utils';;
export interface addCoursewareParams {
  subject: string;
  doc: any;
  cover: any;
  sort: any;
  name: string;
}
export async function addCourseware(params: addCoursewareParams) {
  /* 添加课件 */
  const data = new FormData();
  data.append('subject', params.subject);
  data.append('doc', params.doc);
  data.append('cover', params.cover);
  data.append('sort', params.sort);
  data.append('name', params.name);
  return request(`${baseurl}index/index/courseware`, {
    method: 'POST',
    data,
  });
}

export interface editCoursewareParams {
  subject: any;
  doc: any;
  cover: any;
  docs: any;
  covers: any;
  sort: any;
  name: string;
  id: string;
}
export async function editCourseware(params: editCoursewareParams) {
  /* 编辑课件 */
  const data = new FormData();
  data.append('id', params.id);
  data.append('subject', params.subject);
  data.append('doc', params.doc);
  data.append('cover', params.cover);
  data.append('sort', params.sort);
  data.append('name', params.name);
  data.append('covers', params.covers);
  data.append('docs', params.docs);

  return request(`${baseurl}index/index/courseware_edit`, {
    method: 'POST',
    data,
  });
}

export interface getCoursewareListParams {
  page: string;
  subject: any;
  name: string;
}
export async function getCoursewareList(params: getCoursewareListParams) {
  /* 获取课件列表 */
  const data = new FormData();
  let subject = String(params.subject).replace('251','146').replace('253','146').replace('252','147').replace('254','147');
  data.append('page', params.page);
  data.append('subject', subject);
  data.append('name', params.name);
  return request(`${baseurl}index/index/courseware_list`, {
    method: 'POST',
    data,
  });
}

export interface deleteCoursewareParams {
  id: string;
}
export async function deleteCourseware(params: deleteCoursewareParams) {
  /* 删除课件 */
  const data = new FormData();
  data.append('id', params.id);
  return request(`${baseurl}index/index/courseware_del`, {
    method: 'POST',
    data,
  });
}

export interface getExamAnalyzeParams {
  page: string;
  student_type: any;
  name: string;
  test_name:string
  id_number: string;
  subject:any;
  is_sw:any;
}
export async function getExamAnalyze(params: getExamAnalyzeParams) {
  /* 获取模拟考试统计 */
  const data = new FormData();
  data.append('page', params.page);
  data.append('student_type', params.student_type[params.student_type.length-1]||'');
  data.append('name', params.name);
  data.append('id_number', params.id_number);
  data.append('test_name', params.test_name);
  data.append('subject', params.subject);
  if(hasIsSw()){
    data.append('is_sw', params.is_sw);
  }
  return request(`${baseurl}index/index/topic_statis`, {
    method: 'POST',
    data,
  });
}


export interface getPracticeAnalyzeParams {
  page: string;
  subject: any;
  student_type: any;
  name: string;
  id_number: string;
  is_sw:any;
}
export async function getPracticeAnalyze(params: getPracticeAnalyzeParams) {
  /* 获取练习统计 */
  const data = new FormData();
  data.append('page', params.page);
  data.append('subject', params.subject[params.subject.length-1]||'');
  data.append('student_type', params.student_type[params.student_type.length-1]||'');
  data.append('name', params.name);
  data.append('id_number', params.id_number);
  if(hasIsSw()){
    data.append('is_sw', params.is_sw);
  }
  return request(`${baseurl}index/index/exercise_statistics`, {
    method: 'POST',
    data,
  });
}


export interface getLearnAnalyzeParams {
  page: string;
  subject: any;
  student_type: any;
  name: string;
  id_number: string;
  names:string;
  is_sw:any
}
export async function getLearnAnalyze(params: getLearnAnalyzeParams) {
  /* 获取学习统计 */
  const data = new FormData();
  data.append('page', params.page);
  data.append('subject', params.subject[params.subject.length-1]||'');
  data.append('student_type', params.student_type[params.student_type.length-1]||'');
  data.append('name', params.name);
  data.append('id_number', params.id_number);
  data.append('names', params.names);
  if(hasIsSw()){
    data.append('is_sw', params.is_sw);
  }
  return request(`${baseurl}index/index/courseware_lists`, {
    method: 'POST',
    data,
  });
}


export async function deleteExamAnalyze(params:any) {
  /* 删除模拟统计 */
  const data = new FormData();
  data.append('ids', params.id);
  if(hasIsSw()){
    data.append('is_sw', params.is_sw);
  }
  return request(`${baseurl}index/index/topic_statis_del`, {
    method: 'POST',
    data,
  });
}

export async function deletePracticeAnalyze(params:any) {
  /* 删除练习统计 */
  const data = new FormData();
  data.append('id', params.id);
  if(hasIsSw()){
    data.append('is_sw', params.is_sw);
  }
  return request(`${baseurl}index/index/exercise_statistics_del`, {
    method: 'POST',
    data,
  });
}

export async function deleteLearnAnalyze(params:any) {
  /* 删除学习统计 */
  const data = new FormData();
  data.append('id', params.id);
  if(hasIsSw()){
    data.append('is_sw', params.is_sw);
  }
  return request(`${baseurl}index/index/courseware_lists_del`, {
    method: 'POST',
    data,
  });
}
export async function getPracticeDetail(params:any) {
  /* 获取练习的人详情 */
  const data = new FormData();
  data.append('uid', params.uid);
  if(hasIsSw()){
    data.append('is_sw', params.is_sw);
  }
  return request(`${baseurl}index/index/lianxi`, {
    method: 'POST',
    data,
  });
}


export interface addMaterialParams {
  subject: string;
  doc: any;
  cover: any;
  sort: any;
  name: string;
}
export async function addMaterial(params: addMaterialParams) {
  /* 添加教材 */
  const data = new FormData();
  data.append('subject', params.subject);
  data.append('doc', params.doc);
  data.append('cover', params.cover);
  data.append('sort', params.sort);
  data.append('name', params.name);
  return request(`${baseurl}index/index/coursewares`, {
    method: 'POST',
    data,
  });
}
export interface getMaterialListParams {
  page: string;
  subject: any;
  name: string;
}
export async function getMaterialList(params: getMaterialListParams) {
  /* 获取教材列表 */
  const data = new FormData();
  let subject = String(params.subject).replace('251','146').replace('253','146').replace('252','147').replace('254','147');
  data.append('page', params.page);
  data.append('subject', subject);
  data.append('name', params.name);
  return request(`${baseurl}index/index/courseware_listss`, {
    method: 'POST',
    data,
  });
}